package com.example.buildtable.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.buildtable.pojo.User;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    User user = new User();

    //增加自动填充方法
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "createBy", String.class, user.getName());
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "deleteTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "deleteBy", String.class, user.getName());
        this.strictInsertFill(metaObject, "orderTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "rechargeTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "transferTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "recoveryTime", Date.class, new Date());
    }

    //修改自动填充方法
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateBy", String.class, user.getName());
        this.strictInsertFill(metaObject, "transferTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "recoveryTime", Date.class, new Date());
    }
}
